package game.view.scene
{
	import as3isolib.display.IsoSprite;
	
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.utils.Timer;
	
	import game.controller.GameDispatcher;
	import game.event.EventName;
	import game.event.GameEvent;
	import game.managers.StateManager;


	/**
	 * 厨师类
	 * */
	public class Cooker extends Human
	{
		private var _chefSp:IsoSprite;

		private static const COOKER_REST:int=1;
		private static const COOKER_COOK:int=2;

		private var _cookTimer:Timer;
		/**煮完之后的回调函数*/
		private var _fun:Function;

		/**
		 * @sprite 厨师isosprite对象
		 * */
		public function Cooker(fun:Function)
		{
			if (fun != null) 
			{
				_fun=fun;
			}			
			_cookTimer=new Timer(5000);
		}

		public function isCooking(param:Boolean):void
		{
			if (param)
			{
				_nowState=COOKER_COOK;
				changeState(_chefSp, StateManager.cookerCookLeft);
				
				_cookTimer.start();
				_cookTimer.addEventListener(TimerEvent.TIMER, onCookFinish);
			}
			else
			{
				/**为了防止bug发生,当停顿过久时发送一次事件让顾客离开,让循环可以继续*/
				_nowState=COOKER_REST;
			}
		}
		
		
		private function onCookFinish(e:TimerEvent):void
		{
			changeState(_chefSp, StateManager.cookerRestLeft);
			_nowState=COOKER_REST;

			_cookTimer.removeEventListener(TimerEvent.TIMER, onCookFinish);
			_cookTimer.stop();

			if (_fun != null)
			{
				_fun();
			}

			_nowState=COOKER_REST;

		}

		
		public function get chefSp():IsoSprite
		{
			return _chefSp;
		}

		
		public function set chefSp(value:IsoSprite):void
		{
			_chefSp=value;
		}

		
		override public function dispose():void
		{
			super.dispose();
			_chefSp=null;
			_cookTimer=null;
			_fun=null;
		}

	}
}